-
Notifications
You must be signed in to change notification settings - Fork 475
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add SH1106 display support #846
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really like this! I was hoping oled.py could eventually become display.py, supporting other types of displays and this seems like a great blueprint for that.
I'm approving that, but I'll leave merging up to @xs5871.
Apparently some displays' drivers are built into CircuitPython and do not need any manual initialization. So I added support for those. Interestingly, this includes my own macropad and using this instead of the SH1106 library solves the problem I mentioned earlier:
You would initialize one of these displays like this: import board
from kmk.extensions.oled import Oled, BuiltInDisplay
display_type = BuiltInDisplay(display=board.DISPLAY)
oled = Oled(display_type=display) Of couse, using |
I generally approve, give some time to go into the review. |
Sorry for adding another change after you already started reviewing my pull request, but I discovered that my last change breaks sleep and wake functionality for built-in displays, so I went ahead and fixed it.
Using a import board
from kmk.extensions.oled import Oled, BuiltInDisplay
# Command arguments shown are for example purposes. I assume different displays have different commands for this.
display_type = BuiltInDisplay(display=board.DISPLAY, sleep_command=0xAE, wake_command=0xAF)
oled = Oled(display_type=display) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry it has taken me so long. Here are my thoughts:
- We should rename the
Oled
module toDisplay
. The sooner the better. - This requires documentation. No docs, no merge.
- The
OledDisplayType
class has no shared code and thus doesn't add functionality but will occupy memory. It would enable static type checking, but other than that it's somewhat useless; especially since it's an internal and unlikely to be used actual users. Not a merge blocker, just my opinion. If you want it to stay, it stays. - Not a big fan of the name
OledDisplayType
, specifically the "Type" part of the name. If at all possible, we should avoid overloading language specific nomenclature. We may want to go withDisplayBackend
,DisplayDriver
,DisplayInterface
, ..., or something along those lines.
4.1. Similarly, thedisplay_type
can be shortend to justdisplay
, imo.
7d0d871
to
b1c59b7
Compare
How's this?
|
c2c3560
to
1847989
Compare
1847989
to
b9c23dd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix linter
Thank you! |
Good work @Anomalocaridid @xs5871 ! |
* add support for sh1106 oled displays * replace 'oled' with 'display' --------- Co-authored-by: xs5871 <60395129+xs5871@users.noreply.github.com>
* add support for sh1106 oled displays * replace 'oled' with 'display' --------- Co-authored-by: xs5871 <60395129+xs5871@users.noreply.github.com>
Currently, the OLED extension only supports displays that use the SSD1306 chipset. This PR adds support for displays with the SH1106 chipset.
Essentially, I accomplished this by making both displays display types through subclasses of a new class called
OledDisplayType
. These would be created and passed to the constructor forOled
rather than passing display-specific parameters such as I2C and SPI pins. Display-specific logic is handled by methods in each display's class, which are called by theOled
class's methods with the same names.Using an SH1106 display requires the
adafruit_displayio_sh1106
library, but I made it so that you only need the library for the display(s) you are using by importing them within the displays' classes' methods rather than globally.I did some minor testing and it looks like it works fine. However, I noticed that one short line of pixels one the edge of the screen, presumably from the CircuitPython boot screen, lingers and I am not entirely sure what the cause is. Also I do not own a keyboard with a SSD1306 display, so I need someone else who has one to check that I did not break anything.
Unfortunately, this PR introduces some breaking changes for users and might interfere with #830. However, I am more than happy to wait until #830 gets merged first and then rebase my PR branch and update the documentation myself if necessary.
Instead of initializing the OLED extension with something like:
You would use something like:
For an SH1106 display, it would look like:
Note that for the SH1106 display, it requires pins other than the ones used to create
spi_bus
. Also, I made sure to include the option to just specify the pins and have the classes'__init__()
methods create the I2C/SPI bus for you like it was before.